import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_sample/src/log_util.dart';
import 'package:go_router/go_router.dart';

class PlatformViewPage extends StatefulWidget {
  const PlatformViewPage({super.key});

  @override
  State<PlatformViewPage> createState() => _PlatformViewPageState();
}

class _PlatformViewPageState extends State<PlatformViewPage> {

  final _channel = MethodChannel("com.michaeliu.flutter.study/native_view_0");

  void _updateText() {
    _channel.invokeMethod("updateText",{'text': 'Flutter 触发更新：新文本'});
  }


  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("PlatformViewPage"),
        centerTitle: true,
        leading: IconButton(
          onPressed: () {
            context.pop();
          },
          icon: Icon(Icons.arrow_back_ios_rounded),
        ),
      ),
      body: Column(children: [
        SizedBox(
          height: 150,
          child: AndroidView(viewType: "native_text_view", onPlatformViewCreated: (viewId) {
            logger.i("viewId  $viewId");
          },),
        ),
        ElevatedButton(
          onPressed: _updateText,
          child: const Text('更新原生文本'),
        ),
      ]),
    );
  }
}
